home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / ds3100.md / readline / doc / history.info < prev    next >
Encoding:
Text File  |  1992-07-01  |  17.2 KB  |  552 lines

  1. Info file history.info, produced by Makeinfo, -*- Text -*- from input
  2. file hist.texinfo.
  3.  
  4.    This document describes the GNU History library, a programming
  5. tool that provides a consistent user interface for recalling lines of
  6. previously typed input.
  7.  
  8.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of
  11. this manual provided the copyright notice and this permission notice
  12. pare preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of a
  17. permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that this permission notice may be stated in a
  22. translation approved by the Foundation.
  23.  
  24.  
  25. 
  26. File: history.info,  Node: Top
  27.  
  28.    GNU History Library
  29.  
  30.    This document describes the GNU History library, a programming
  31. tool that provides a consistent user interface for recalling lines of
  32. previously typed input.
  33.  
  34. * Menu:
  35.  
  36. * Using History Interactively::      GNU History User's Manual.
  37. * Programming with GNU History::  GNU History Programmer's Manual.
  38. * Concept Index::          Index of concepts described in this manual.
  39. * Function and Variable Index::      Index of externally visible functions
  40.                   and variables.
  41.  
  42.  
  43. 
  44. File: history.info,  Node: Using History Interactively,  Next: Programming with GNU History,  Up: Top
  45.  
  46. Using History Interactively
  47. ***************************
  48.  
  49.    This chapter describes how to use the GNU History Library
  50. interactively, from a user's standpoint.  It should be considered a
  51. user's guide.  For information on using the GNU History Library in
  52. your own programs, *note Programming with GNU History::..
  53.  
  54. * Menu:
  55.  
  56. * History Interaction::        What it feels like using History as a user.
  57.  
  58.  
  59. 
  60. File: history.info,  Node: History Interaction,  Prev: Programming with GNU History,  Up: Using History Interactively
  61.  
  62. History Interaction
  63. ===================
  64.  
  65.    The History library provides a history expansion feature that is
  66. similar to the history expansion in Csh.  The following text
  67. describes the sytax that you use to manipulate the history information.
  68.  
  69.    History expansion takes place in two parts.  The first is to
  70. determine which line from the previous history should be used during
  71. substitution.  The second is to select portions of that line for
  72. inclusion into the current one.  The line selected from the previous
  73. history is called the "event", and the portions of that line that are
  74. acted upon are called "words".  The line is broken into words in the
  75. same fashion that the Bash shell does, so that several English (or
  76. Unix) words surrounded by quotes are considered as one word.
  77.  
  78. * Menu:
  79.  
  80. * Event Designators::    How to specify which history line to use.
  81. * Word Designators::    Specifying which words are of interest.
  82. * Modifiers::        Modifying the results of susbstitution.
  83.  
  84.  
  85. 
  86. File: history.info,  Node: Event Designators,  Next: Word Designators,  Up: History Interaction
  87.  
  88. Event Designators
  89. -----------------
  90.  
  91.    An event designator is a reference to a command line entry in the
  92. history list.
  93.  
  94. `!'
  95.      Start a history subsititution, except when followed by a space,
  96.      tab, or the end of the line... = or (.
  97.  
  98. `!!'
  99.      Refer to the previous command.  This is a synonym for `!-1'.
  100.  
  101. `!n'
  102.      Refer to command line N.
  103.  
  104. `!-n'
  105.      Refer to the command line N lines back.
  106.  
  107. `!string'
  108.      Refer to the most recent command starting with STRING.
  109.  
  110. `!?string'[`?']
  111.      Refer to the most recent command containing STRING.
  112.  
  113.  
  114. 
  115. File: history.info,  Node: Word Designators,  Next: Modifiers,  Prev: Event Designators,  Up: History Interaction
  116.  
  117. Word Designators
  118. ----------------
  119.  
  120.    A : separates the event specification from the word designator. 
  121. It can be omitted if the word designator begins with a ^, $, * or %. 
  122. Words are numbered from the beginning of the line, with the first
  123. word being denoted by a 0 (zero).
  124.  
  125. `0 (zero)'
  126.      The zero'th word.  For many applications, this is the command
  127.      word.
  128.  
  129. `n'
  130.      The N'th word.
  131.  
  132. `^'
  133.      The first argument.  that is, word 1.
  134.  
  135. `$'
  136.      The last argument.
  137.  
  138. `%'
  139.      The word matched by the most recent `?string?' search.
  140.  
  141. `x-y'
  142.      A range of words; `-Y' Abbreviates `0-Y'.
  143.  
  144. `*'
  145.      All of the words, excepting the zero'th.  This is a synonym for
  146.      `1-$'.  It is not an error to use * if there is just one word in
  147.      the event.  The empty string is returned in that case.
  148.  
  149.  
  150. 
  151. File: history.info,  Node: Modifiers,  Prev: Word Designators,  Up: History Interaction
  152.  
  153. Modifiers
  154. ---------
  155.  
  156.    After the optional word designator, you can add a sequence of one
  157. or more of the following modifiers, each preceded by a :.
  158.  
  159. `#'
  160.      The entire command line typed so far.  This means the current
  161.      command, not the previous command, so it really isn't a word
  162.      designator, and doesn't belong in this section.
  163.  
  164. `h'
  165.      Remove a trailing pathname component, leaving only the head.
  166.  
  167. `r'
  168.      Remove a trailing suffix of the form `.'SUFFIX, leaving the
  169.      basename.
  170.  
  171. `e'
  172.      Remove all but the suffix.
  173.  
  174. `t'
  175.      Remove all leading  pathname  components, leaving the tail.
  176.  
  177. `p'
  178.      Print the new command but do not execute it.
  179.  
  180.  
  181. 
  182. File: history.info,  Node: Programming with GNU History,  Next: Concept Index,  Prev: Using History Interactively,  Up: Top
  183.  
  184. Programming with GNU History
  185. ****************************
  186.  
  187.    This chapter describes how to interface the GNU History Library
  188. with programs that you write.  It should be considered a technical
  189. guide.  For information on the interactive use of GNU History, *note
  190. Using History Interactively::..
  191.  
  192. * Menu:
  193.  
  194. * Introduction to History::    What is the GNU History library for?
  195. * History Storage::        How information is stored.
  196. * History Functions::        Functions that you can use.
  197. * History Variables::        Variables that control behaviour.
  198. * History Programming Example::    Example of using the GNU History Library.
  199.  
  200.  
  201. 
  202. File: history.info,  Node: Introduction to History,  Next: History Storage,  Prev: Using History Interactively,  Up: Programming with GNU History
  203.  
  204. Introduction to History
  205. =======================
  206.  
  207.    Many programs read input from the user a line at a time.  The GNU
  208. history library is able to keep track of those lines, associate
  209. arbitrary data with each line, and utilize information from previous
  210. lines in making up new ones.
  211.  
  212.    The programmer using the History library has available to him
  213. functions for remembering lines on a history stack, associating
  214. arbitrary data with a line, removing lines from the stack, searching
  215. through the stack for a line containing an arbitrary text string, and
  216. referencing any line on the stack directly.  In addition, a history
  217. "expansion" function is available which provides for a consistent
  218. user interface across many different programs.
  219.  
  220.    The end-user using programs written with the History library has
  221. the benifit of a consistent user interface, with a set of well-known
  222. commands for manipulating the text of previous lines and using that
  223. text in new commands.  The basic history manipulation commands are
  224. similar to the history substitution used by `Csh'.
  225.  
  226.    If the programmer desires, he can use the Readline library, which
  227. includes some history manipulation by default, and has the added
  228. advantage of Emacs style command line editing.
  229.  
  230.  
  231. 
  232. File: history.info,  Node: History Storage,  Next: History Functions,  Prev: Introduction to History,  Up: Programming with GNU History
  233.  
  234. History Storage
  235. ===============
  236.  
  237.      typedef struct _hist_entry {
  238.        char *line;
  239.        char *data;
  240.      } HIST_ENTRY;
  241.  
  242.  
  243. 
  244. File: history.info,  Node: History Functions,  Next: History Variables,  Prev: History Storage,  Up: Programming with GNU History
  245.  
  246. History Functions
  247. =================
  248.  
  249.    This section describes the calling sequence for the various
  250. functions present in GNU History.
  251.  
  252.  * Function: void using_history ()
  253.  
  254.      Begin a session in which the history functions might be used. 
  255.      This just initializes the interactive variables.
  256.  
  257.  * Function: void add_history (CHAR *STRING)
  258.  
  259.      Place STRING at the end of the history list.  The associated
  260.      data field (if any) is set to `NULL'.
  261.  
  262.  * Function: int where_history ()
  263.  
  264.      Returns the number which says what history element we are now
  265.      looking at.
  266.  
  267.  * Function: int history_set_pos (INT POS)
  268.  
  269.      Set the position in the history list to POS.
  270.  
  271.  * Function: int history_search_pos (CHAR *STRING, INT DIRECTION, INT
  272. POS)
  273.  
  274.      Search for STRING in the history list, starting at POS, an
  275.      absolute index into the list.  DIRECTION, if negative, says to
  276.      search backwards from POS, else forwards.  Returns the absolute
  277.      index of the history element where STRING was found, or -1
  278.      otherwise.
  279.  
  280.  * Function: HIST_ENTRY *remove_history ();
  281.  
  282.      Remove history element WHICH from the history.  The removed
  283.      element is returned to you so you can free the line, data, and
  284.      containing structure.
  285.  
  286.  * Function: void stifle_history (INT MAX)
  287.  
  288.      Stifle the history list, remembering only MAX number of entries.
  289.  
  290.  * Function: int unstifle_history ();
  291.  
  292.      Stop stifling the history.  This returns the previous amount the
  293.      history was stifled by.  The value is positive if the history
  294.      was stifled, negative if it wasn't.
  295.  
  296.  * Function: int read_history (CHAR *FILENAME)
  297.  
  298.      Add the contents of FILENAME to the history list, a line at a
  299.      time.  If FILENAME is `NULL', then read from `~/.history'. 
  300.      Returns 0 if successful, or errno if not.
  301.  
  302.  * Function: int read_history_range (CHAR *FILENAME, INT FROM, INT TO)
  303.  
  304.      Read a range of lines from FILENAME, adding them to the history
  305.      list.  Start reading at the FROM'th line and end at the TO'th. 
  306.      If FROM is zero, start at the beginning.  If TO is less than
  307.      FROM, then read until the end of the file.  If FILENAME is
  308.      `NULL', then read from `~/.history'.  Returns 0 if successful,
  309.      or `errno' if not.
  310.  
  311.  * Function: int write_history (CHAR *FILENAME)
  312.  
  313.      Append the current history to FILENAME.  If FILENAME is `NULL',
  314.      then append the history list to `~/.history'.  Values returned
  315.      are as in `read_history ()'.
  316.  
  317.  * Function: int append_history (INT NELEMENTS, CHAR *FILENAME)
  318.  
  319.      Append NELEMENT entries to FILENAME.  The entries appended are
  320.      from the end of the list minus NELEMENTS up to the end of the
  321.      list.
  322.  
  323.  * Function: HIST_ENTRY *replace_history_entry ()
  324.  
  325.      Make the history entry at WHICH have LINE and DATA.  This
  326.      returns the old entry so you can dispose of the data.  In the
  327.      case of an invalid WHICH, a `NULL' pointer is returned.
  328.  
  329.  * Function: HIST_ENTRY *current_history ()
  330.  
  331.      Return the history entry at the current position, as determined
  332.      by `history_offset'.  If there is no entry there, return a
  333.      `NULL' pointer.
  334.  
  335.  * Function: HIST_ENTRY *previous_history ()
  336.  
  337.      Back up HISTORY_OFFSET to the previous history entry, and return
  338.      a pointer to that entry.  If there is no previous entry, return
  339.      a `NULL' pointer.
  340.  
  341.  * Function: HIST_ENTRY *next_history ()
  342.  
  343.      Move `history_offset' forward to the next history entry, and
  344.      return the a pointer to that entry.  If there is no next entry,
  345.      return a `NULL' pointer.
  346.  
  347.  * Function: HIST_ENTRY **history_list ()
  348.  
  349.      Return a `NULL' terminated array of `HIST_ENTRY' which is the
  350.      current input history.  Element 0 of this list is the beginning
  351.      of time.  If there is no history, return `NULL'.
  352.  
  353.  * Function: int history_search (CHAR *STRING, INT DIRECTION)
  354.  
  355.      Search the history for STRING, starting at `history_offset'.  If
  356.      DIRECTION < 0, then the search is through previous entries, else
  357.      through subsequent.  If STRING is found, then `current_history
  358.      ()' is the history entry, and the value of this function is the
  359.      offset in the line of that history entry that the STRING was
  360.      found in.  Otherwise, nothing is changed, and a -1 is returned.
  361.  
  362.  * Function: int history_expand (CHAR *STRING, CHAR **OUTPUT)
  363.  
  364.      Expand STRING, placing the result into OUTPUT, a pointer to a
  365.      string.  Returns:
  366.  
  367.     `0'
  368.           If no expansions took place (or, if the only change in the
  369.           text was the de-slashifying of the history expansion
  370.           character),
  371.  
  372.     `1'
  373.           if expansions did take place, or
  374.  
  375.     `-1'
  376.           if there was an error in expansion.
  377.  
  378.      If an error ocurred in expansion, then OUTPUT contains a
  379.      descriptive error message.
  380.  
  381.  * Function: char *history_arg_extract (INT FIRST, INT LAST, CHAR
  382. *STRING)
  383.  
  384.      Extract a string segment consisting of the FIRST through LAST
  385.      arguments present in STRING.  Arguments are broken up as in the
  386.      GNU Bash shell.
  387.  
  388.  * Function: int history_total_bytes ();
  389.  
  390.      Return the number of bytes that the primary history entries are
  391.      using.  This just adds up the lengths of `the_history->lines'.
  392.  
  393.  
  394. 
  395. File: history.info,  Node: History Variables,  Next: History Programming Example,  Prev: History Functions,  Up: Programming with GNU History
  396.  
  397. History Variables
  398. =================
  399.  
  400.    This section describes the variables in GNU History that are
  401. externally visible.
  402.  
  403.  * Variable: int history_base
  404.  
  405.      For convenience only.  You set this when interpreting history
  406.      commands.  It is the logical offset of the first history element.
  407.  
  408.  
  409. 
  410. File: history.info,  Node: History Programming Example,  Prev: History Variables,  Up: Programming with GNU History
  411.  
  412. History Programming Example
  413. ===========================
  414.  
  415.    The following snippet of code demonstrates simple use of the GNU
  416. History Library.
  417.  
  418.      main ()
  419.      {
  420.        char line[1024], *t;
  421.        int done = 0;
  422.      
  423.        line[0] = 0;
  424.      
  425.        while (!done)
  426.          {
  427.            fprintf (stdout, "history%% ");
  428.            t = gets (line);
  429.      
  430.            if (!t)
  431.              strcpy (line, "quit");
  432.      
  433.            if (line[0])
  434.              {
  435.                char *expansion;
  436.                int result;
  437.      
  438.                using_history ();
  439.      
  440.                result = history_expand (line, &expansion);
  441.                strcpy (line, expansion);
  442.                free (expansion);
  443.                if (result)
  444.                  fprintf (stderr, "%s\n", line);
  445.      
  446.                if (result < 0)
  447.                  continue;
  448.      
  449.                add_history (line);
  450.              }
  451.      
  452.            if (strcmp (line, "quit") == 0) done = 1;
  453.            if (strcmp (line, "save") == 0) write_history (0);
  454.            if (strcmp (line, "read") == 0) read_history (0);
  455.            if (strcmp (line, "list") == 0)
  456.              {
  457.                register HIST_ENTRY **the_list = history_list ();
  458.                register int i;
  459.      
  460.                if (the_list)
  461.                  for (i = 0; the_list[i]; i++)
  462.                    fprintf (stdout, "%d: %s\n",
  463.                       i + history_base, the_list[i]->line);
  464.              }
  465.            if (strncmp (line, "delete", strlen ("delete")) == 0)
  466.              {
  467.                int which;
  468.                if ((sscanf (line + strlen ("delete"), "%d", &which)) == 1)
  469.                  {
  470.                    HIST_ENTRY *entry = remove_history (which);
  471.                    if (!entry)
  472.                      fprintf (stderr, "No such entry %d\n", which);
  473.                    else
  474.                      {
  475.                        free (entry->line);
  476.                        free (entry);
  477.                      }
  478.                  }
  479.                else
  480.                  {
  481.                    fprintf (stderr, "non-numeric arg given to `delete'\n");
  482.                  }
  483.              }
  484.          }
  485.      }
  486.  
  487.  
  488. 
  489. File: history.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU History,  Up: Top
  490.  
  491. Concept Index
  492. *************
  493.  
  494. * Menu:
  495.  
  496. * event designators: Event Designators.
  497. * expansion: History Interaction.
  498.  
  499.  
  500.  
  501. 
  502. File: history.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  503.  
  504. Function and Variable Index
  505. ***************************
  506.  
  507. * Menu:
  508.  
  509. * HIST_ENTRY **history_list: History Functions.
  510. * HIST_ENTRY *current_history: History Functions.
  511. * HIST_ENTRY *next_history: History Functions.
  512. * HIST_ENTRY *previous_history: History Functions.
  513. * HIST_ENTRY *remove_history: History Functions.
  514. * HIST_ENTRY *replace_history_entry: History Functions.
  515. * char *history_arg_extract: History Functions.
  516. * int append_history: History Functions.
  517. * int history_base: History Variables.
  518. * int history_expand: History Functions.
  519. * int history_search: History Functions.
  520. * int history_search_pos: History Functions.
  521. * int history_set_pos: History Functions.
  522. * int history_total_bytes: History Functions.
  523. * int read_history: History Functions.
  524. * int read_history_range: History Functions.
  525. * int unstifle_history: History Functions.
  526. * int where_history: History Functions.
  527. * int write_history: History Functions.
  528. * void add_history: History Functions.
  529. * void stifle_history: History Functions.
  530. * void using_history: History Functions.
  531.  
  532.  
  533.  
  534.    
  535. Tag Table:
  536. Node: Top973
  537. Node: Using History Interactively1489
  538. Node: History Interaction1987
  539. Node: Event Designators3078
  540. Node: Word Designators3723
  541. Node: Modifiers4630
  542. Node: Programming with GNU History5380
  543. Node: Introduction to History6108
  544. Node: History Storage7496
  545. Node: History Functions7761
  546. Node: History Variables13055
  547. Node: History Programming Example13493
  548. Node: Concept Index15739
  549. Node: Function and Variable Index15981
  550. 
  551. End Tag Table
  552.